<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Order extends MY_Controller {
	
	function __construct(){
		parent::__construct();
		$this->load->model('order/OrderModel', '' , true);
	}
	
	/*
	 * 订单首页
	 */
	function index($index=1,$size=10){
		$this->load->model('order/FromModel', '' , true);
		$this->load->model('order/ExpressModel', '' , true);
		$view_data['froms'] = $this->FromModel->selectAll();
		$view_data['expresses'] = $this->ExpressModel->selectAll();
		$this->load->view('order/index',$view_data);
	}
	
	function data_list($index=1,$size=10){
		$view_data = $this->_data($index,$size);
		$this->load->view('order/data_list',$view_data);
	}
	
	function _data($index=1,$size=20) {
		$result = $this->OrderModel->select($index,$size);
		$data['list'] = $result['data'];
		$this->load->library('pagination');
		$data['pages'] = $this->pagination->get_pages(base_url().index_page().'/order/index',$result['total'],$size,$index);
		return $data;
	}
	/*
	 * exist 检测订单单号否存在
	 */
	function existNumber($number) {
		$data['state'] = $this->OrderModel->isExistNumber($number);
		$this->_output_json($data);
	}
	
	/*
	 * 发货列表
	 */
	function s(){
		$this->load->view('order/s');
	}
	
	/*
	 * 添加订单
	 */
	function add(){
		$customer = $this->input->post('customer',true);
		$this->load->model('customer/CustomerModel', '' , true);
		$id = $this->CustomerModel->insert($customer);
		if($id > 0){
			$customer['id'] = $id;
			$view_data['customer'] = $customer;
			$data['html'] = $this->load->view('order/add_edit',$view_data,true);
			$data['state'] = 1;
			$data['message'] = '第一步：填写基本信息 成功，请添加订单产品信息。';
		}else{
			$data['message'] = '第一步：填写基本信息 失败！';
		}
		$this->_output_json($data);
	}
}
?>